package sanrenxing.dayEnd.backRepertoryTotal.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sanrenxing.dayEnd.backRepertoryTotal.dao.ManagerSetupDao;
import sanrenxing.dayEnd.backRepertoryTotal.domain.ManagerSetup;
import sanrenxing.dayEnd.backRepertoryTotal.service.ManagerSetupBiz;

import java.util.HashMap;
import java.util.List;

/**
 * 功能：管理人业务层接口实现类
 * 编写者：蒋玲苹
 * 日期：
 * 版本：1.0
 */
@Service
public class ManagerSetupBizImpl implements ManagerSetupBiz {
    @Autowired
    private ManagerSetupDao managerSetupDao;
    /**
     * 添加数据
     *
     * @param managerSetup
     * @return 0:添加失败,1:添加成功
     */
    @Override
    public int add(ManagerSetup managerSetup) {
        return managerSetupDao.add(managerSetup);
    }

    /**
     * 删除数据
     *
     * @param adminIds
     * @return 删除影响的行数(0 : 删除失败, 1 : 删除成功)
     */
    @Override
    public int delete(String adminIds) {
        //判断是否为批量删除
        if(adminIds.contains(",")){
            //对编号按“，”分割
            String[] strs=adminIds.split(",");
            //循环删除
            for(String str:strs){
                //调用方法删除
                managerSetupDao.delete(Integer.parseInt(str));
            }
            //返回1
            return 1;
        }
        return managerSetupDao.delete(Integer.parseInt(adminIds));
    }

    /**
     * 修改数据
     *
     * @param managerSetup
     * @return
     */
    @Override
    public int update(ManagerSetup managerSetup) {
        return managerSetupDao.update(managerSetup);
    }

    /**
     * 分页查询所有数据
     *
     * @param managerSetup
     * @param row
     * @param page
     * @return
     */
    @Override
    public List<ManagerSetup> queryAll(ManagerSetup managerSetup, int row, int page) {
        HashMap<String,Object> map=new HashMap<>();
        map.put("managerSetup",managerSetup);
        map.put("start",page);
        map.put("end",(page+row));
        return managerSetupDao.queryAll(map);
    }

    /**
     * 统计记录数
     *
     * @param managerSetup
     * @return
     */
    @Override
    public int count(ManagerSetup managerSetup) {
        return managerSetupDao.count();
    }
}
